package com.sjy.ylxt.controller;


import com.sjy.ylxt.entity.basic.ResultBody;
import com.sjy.ylxt.entity.domain.Notification;
import com.sjy.ylxt.service.NotificationService;
import com.sjy.ylxt.utils.SnowFlakeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;
/**
 * 通知管理
 */
@RestController
@RequestMapping("/notifications")
public class NotificationController {

    @Resource
    private NotificationService notificationService;

    @GetMapping("/list")
    public ResultBody<?> getAllNotifications() {
        return ResultBody.success(notificationService.getAllNotifications());
    }

    @PostMapping("/add")
    public ResultBody<?> addNotification(
            @RequestParam @NotBlank(message = "标题不能为空") String title,
            @RequestParam @NotBlank(message = "内容不能为空") String content) {
        Notification notification = new Notification();
        notification.setTitle(title);
        notification.setContent(content);
        notification.setId(SnowFlakeUtil.getInstance().nextId());
        notification.setCreatedAt(new java.util.Date());
        notification.setUpdatedAt(new java.util.Date());
        notificationService.addNotification(notification);
        return ResultBody.success("通知添加成功");
    }
}



